<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>Kernel Information and Control</title>
<title>CMSIS-RTOS2: Kernel Information and Control</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="cmsis.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<script type="text/javascript" src="printComponentTabs.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
  $(window).load(resizeHeight);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 46px;">
  <td id="projectlogo"><img alt="Logo" src="CMSIS_Logo_Final.png"/></td>
  <td style="padding-left: 0.5em;">
   <div id="projectname">CMSIS-RTOS2
   &#160;<span id="projectnumber">Version 2.1.3</span>
   </div>
   <div id="projectbrief">Real-Time Operating System: API and RTX Reference Implementation</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<div id="CMSISnav" class="tabs1">
    <ul class="tablist">
      <script type="text/javascript">
		<!--
		writeComponentTabs.call(this);
		//-->
      </script>
	  </ul>
</div>
<!-- Generated by Doxygen 1.8.6 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Usage&#160;and&#160;Description</span></a></li>
      <li><a href="modules.html"><span>Reference</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('group__CMSIS__RTOS__KernelCtrl.html','');});
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Data Structures</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark">&#160;</span>Macros</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(9)"><span class="SelectionMark">&#160;</span>Groups</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(10)"><span class="SelectionMark">&#160;</span>Pages</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="summary">
<a href="#nested-classes">Data Structures</a> &#124;
<a href="#enum-members">Enumerations</a> &#124;
<a href="#func-members">Functions</a>  </div>
  <div class="headertitle">
<div class="title">Kernel Information and Control<div class="ingroups"><a class="el" href="group__CMSIS__RTOS.html">CMSIS-RTOS API v2</a></div></div>  </div>
</div><!--header-->
<div class="contents">

<p>Provides version/system information and starts/controls the RTOS Kernel.  
<a href="#details">More...</a></p>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="nested-classes"></a>
Data Structures</h2></td></tr>
<tr class="memitem:structosVersion__t"><td class="memItemLeft" align="right" valign="top">struct &#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__CMSIS__RTOS__KernelCtrl.html#structosVersion__t">osVersion_t</a></td></tr>
<tr class="memdesc:structosVersion__t"><td class="mdescLeft">&#160;</td><td class="mdescRight">Version information.  <a href="group__CMSIS__RTOS__KernelCtrl.html#structosVersion__t">More...</a><br/></td></tr>
<tr class="separator:structosVersion__t"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="enum-members"></a>
Enumerations</h2></td></tr>
<tr class="memitem:ga08326469274b668140ca934b168a5ad4"><td class="memItemLeft" align="right" valign="top">enum &#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__CMSIS__RTOS__KernelCtrl.html#ga08326469274b668140ca934b168a5ad4">osKernelState_t</a> { <br/>
&#160;&#160;<a class="el" href="group__CMSIS__RTOS__KernelCtrl.html#ga08326469274b668140ca934b168a5ad4a2ad3e5912db47b497529d036c89e7995">osKernelInactive</a> = 0, 
<br/>
&#160;&#160;<a class="el" href="group__CMSIS__RTOS__KernelCtrl.html#ga08326469274b668140ca934b168a5ad4a0596c6e14113447604753656417c9a24">osKernelReady</a> = 1, 
<br/>
&#160;&#160;<a class="el" href="group__CMSIS__RTOS__KernelCtrl.html#ga08326469274b668140ca934b168a5ad4a8e0b699fbe1c8bb66fefadd5911cb6ce">osKernelRunning</a> = 2, 
<br/>
&#160;&#160;<a class="el" href="group__CMSIS__RTOS__KernelCtrl.html#ga08326469274b668140ca934b168a5ad4a2fe382ad5ebab2257b35740414b28b01">osKernelLocked</a> = 3, 
<br/>
&#160;&#160;<a class="el" href="group__CMSIS__RTOS__KernelCtrl.html#ga08326469274b668140ca934b168a5ad4ad364464ad84d63b1413a9ac8a962390c">osKernelSuspended</a> = 4, 
<br/>
&#160;&#160;<a class="el" href="group__CMSIS__RTOS__KernelCtrl.html#ga08326469274b668140ca934b168a5ad4a0545c92c18ce8e6b24e82a0d694a0b4a">osKernelError</a> = -1, 
<br/>
&#160;&#160;<a class="el" href="group__CMSIS__RTOS__KernelCtrl.html#ga08326469274b668140ca934b168a5ad4ab0a47576defa29396a649d9173d4bc4b">osKernelReserved</a> = 0x7FFFFFFFU
<br/>
 }</td></tr>
<tr class="memdesc:ga08326469274b668140ca934b168a5ad4"><td class="mdescLeft">&#160;</td><td class="mdescRight">Kernel state.  <a href="group__CMSIS__RTOS__KernelCtrl.html#ga08326469274b668140ca934b168a5ad4">More...</a><br/></td></tr>
<tr class="separator:ga08326469274b668140ca934b168a5ad4"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="func-members"></a>
Functions</h2></td></tr>
<tr class="memitem:gae818f6611d25ba3140bede410a52d659"><td class="memItemLeft" align="right" valign="top"><a class="el" href="group__CMSIS__RTOS__Definitions.html#ga6c0dbe6069e4e7f47bb4cd32ae2b813e">osStatus_t</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__CMSIS__RTOS__KernelCtrl.html#gae818f6611d25ba3140bede410a52d659">osKernelInitialize</a> (void)</td></tr>
<tr class="memdesc:gae818f6611d25ba3140bede410a52d659"><td class="mdescLeft">&#160;</td><td class="mdescRight">Initialize the RTOS Kernel.  <a href="#gae818f6611d25ba3140bede410a52d659">More...</a><br/></td></tr>
<tr class="separator:gae818f6611d25ba3140bede410a52d659"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga6f7764e7250c5c5364c00c45a5d1d199"><td class="memItemLeft" align="right" valign="top"><a class="el" href="group__CMSIS__RTOS__Definitions.html#ga6c0dbe6069e4e7f47bb4cd32ae2b813e">osStatus_t</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__CMSIS__RTOS__KernelCtrl.html#ga6f7764e7250c5c5364c00c45a5d1d199">osKernelGetInfo</a> (<a class="el" href="group__CMSIS__RTOS__KernelCtrl.html#structosVersion__t">osVersion_t</a> *version, char *id_buf, uint32_t id_size)</td></tr>
<tr class="memdesc:ga6f7764e7250c5c5364c00c45a5d1d199"><td class="mdescLeft">&#160;</td><td class="mdescRight">Get RTOS Kernel Information.  <a href="#ga6f7764e7250c5c5364c00c45a5d1d199">More...</a><br/></td></tr>
<tr class="separator:ga6f7764e7250c5c5364c00c45a5d1d199"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga48b69b81012fce051f639be288b243ba"><td class="memItemLeft" align="right" valign="top"><a class="el" href="group__CMSIS__RTOS__KernelCtrl.html#ga08326469274b668140ca934b168a5ad4">osKernelState_t</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__CMSIS__RTOS__KernelCtrl.html#ga48b69b81012fce051f639be288b243ba">osKernelGetState</a> (void)</td></tr>
<tr class="memdesc:ga48b69b81012fce051f639be288b243ba"><td class="mdescLeft">&#160;</td><td class="mdescRight">Get the current RTOS Kernel state.  <a href="#ga48b69b81012fce051f639be288b243ba">More...</a><br/></td></tr>
<tr class="separator:ga48b69b81012fce051f639be288b243ba"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga9ae2cc00f0d89d7b6a307bba942b5221"><td class="memItemLeft" align="right" valign="top"><a class="el" href="group__CMSIS__RTOS__Definitions.html#ga6c0dbe6069e4e7f47bb4cd32ae2b813e">osStatus_t</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__CMSIS__RTOS__KernelCtrl.html#ga9ae2cc00f0d89d7b6a307bba942b5221">osKernelStart</a> (void)</td></tr>
<tr class="memdesc:ga9ae2cc00f0d89d7b6a307bba942b5221"><td class="mdescLeft">&#160;</td><td class="mdescRight">Start the RTOS Kernel scheduler.  <a href="#ga9ae2cc00f0d89d7b6a307bba942b5221">More...</a><br/></td></tr>
<tr class="separator:ga9ae2cc00f0d89d7b6a307bba942b5221"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga948609ee930d9b38336b9e1c2a4dfe12"><td class="memItemLeft" align="right" valign="top">int32_t&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__CMSIS__RTOS__KernelCtrl.html#ga948609ee930d9b38336b9e1c2a4dfe12">osKernelLock</a> (void)</td></tr>
<tr class="memdesc:ga948609ee930d9b38336b9e1c2a4dfe12"><td class="mdescLeft">&#160;</td><td class="mdescRight">Lock the RTOS Kernel scheduler.  <a href="#ga948609ee930d9b38336b9e1c2a4dfe12">More...</a><br/></td></tr>
<tr class="separator:ga948609ee930d9b38336b9e1c2a4dfe12"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gaf401728b4657456198c33fe75f8d6720"><td class="memItemLeft" align="right" valign="top">int32_t&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__CMSIS__RTOS__KernelCtrl.html#gaf401728b4657456198c33fe75f8d6720">osKernelUnlock</a> (void)</td></tr>
<tr class="memdesc:gaf401728b4657456198c33fe75f8d6720"><td class="mdescLeft">&#160;</td><td class="mdescRight">Unlock the RTOS Kernel scheduler.  <a href="#gaf401728b4657456198c33fe75f8d6720">More...</a><br/></td></tr>
<tr class="separator:gaf401728b4657456198c33fe75f8d6720"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gae7d0a71b9586cbbb49fcbdf6a04f0289"><td class="memItemLeft" align="right" valign="top">int32_t&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__CMSIS__RTOS__KernelCtrl.html#gae7d0a71b9586cbbb49fcbdf6a04f0289">osKernelRestoreLock</a> (int32_t lock)</td></tr>
<tr class="memdesc:gae7d0a71b9586cbbb49fcbdf6a04f0289"><td class="mdescLeft">&#160;</td><td class="mdescRight">Restore the RTOS Kernel scheduler lock state.  <a href="#gae7d0a71b9586cbbb49fcbdf6a04f0289">More...</a><br/></td></tr>
<tr class="separator:gae7d0a71b9586cbbb49fcbdf6a04f0289"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gae26683e1606ec633354a2876c68f0c1f"><td class="memItemLeft" align="right" valign="top">uint32_t&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__CMSIS__RTOS__KernelCtrl.html#gae26683e1606ec633354a2876c68f0c1f">osKernelSuspend</a> (void)</td></tr>
<tr class="memdesc:gae26683e1606ec633354a2876c68f0c1f"><td class="mdescLeft">&#160;</td><td class="mdescRight">Suspend the RTOS Kernel scheduler.  <a href="#gae26683e1606ec633354a2876c68f0c1f">More...</a><br/></td></tr>
<tr class="separator:gae26683e1606ec633354a2876c68f0c1f"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga8c4b4d7ed34cab73c001665d9176aced"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__CMSIS__RTOS__KernelCtrl.html#ga8c4b4d7ed34cab73c001665d9176aced">osKernelResume</a> (uint32_t sleep_ticks)</td></tr>
<tr class="memdesc:ga8c4b4d7ed34cab73c001665d9176aced"><td class="mdescLeft">&#160;</td><td class="mdescRight">Resume the RTOS Kernel scheduler.  <a href="#ga8c4b4d7ed34cab73c001665d9176aced">More...</a><br/></td></tr>
<tr class="separator:ga8c4b4d7ed34cab73c001665d9176aced"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga84bcdbf2fb76b10c8df4e439f0c7e11b"><td class="memItemLeft" align="right" valign="top">uint32_t&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__CMSIS__RTOS__KernelCtrl.html#ga84bcdbf2fb76b10c8df4e439f0c7e11b">osKernelGetTickCount</a> (void)</td></tr>
<tr class="memdesc:ga84bcdbf2fb76b10c8df4e439f0c7e11b"><td class="mdescLeft">&#160;</td><td class="mdescRight">Get the RTOS kernel tick count.  <a href="#ga84bcdbf2fb76b10c8df4e439f0c7e11b">More...</a><br/></td></tr>
<tr class="separator:ga84bcdbf2fb76b10c8df4e439f0c7e11b"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga7a8d7bd927eaaa58999f91d7d6310cee"><td class="memItemLeft" align="right" valign="top">uint32_t&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__CMSIS__RTOS__KernelCtrl.html#ga7a8d7bd927eaaa58999f91d7d6310cee">osKernelGetTickFreq</a> (void)</td></tr>
<tr class="memdesc:ga7a8d7bd927eaaa58999f91d7d6310cee"><td class="mdescLeft">&#160;</td><td class="mdescRight">Get the RTOS kernel tick frequency.  <a href="#ga7a8d7bd927eaaa58999f91d7d6310cee">More...</a><br/></td></tr>
<tr class="separator:ga7a8d7bd927eaaa58999f91d7d6310cee"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:gae0fcaff6cecfb4013bb556c87afcd7d2"><td class="memItemLeft" align="right" valign="top">uint32_t&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__CMSIS__RTOS__KernelCtrl.html#gae0fcaff6cecfb4013bb556c87afcd7d2">osKernelGetSysTimerCount</a> (void)</td></tr>
<tr class="memdesc:gae0fcaff6cecfb4013bb556c87afcd7d2"><td class="mdescLeft">&#160;</td><td class="mdescRight">Get the RTOS kernel system timer count.  <a href="#gae0fcaff6cecfb4013bb556c87afcd7d2">More...</a><br/></td></tr>
<tr class="separator:gae0fcaff6cecfb4013bb556c87afcd7d2"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ga4d69215a93220f72be3684cad582f16a"><td class="memItemLeft" align="right" valign="top">uint32_t&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__CMSIS__RTOS__KernelCtrl.html#ga4d69215a93220f72be3684cad582f16a">osKernelGetSysTimerFreq</a> (void)</td></tr>
<tr class="memdesc:ga4d69215a93220f72be3684cad582f16a"><td class="mdescLeft">&#160;</td><td class="mdescRight">Get the RTOS kernel system timer frequency.  <a href="#ga4d69215a93220f72be3684cad582f16a">More...</a><br/></td></tr>
<tr class="separator:ga4d69215a93220f72be3684cad582f16a"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Description</h2>
<p>The kernel Information and Control function group allows to:</p>
<ul>
<li>obtain information about the system and the underlying kernel.</li>
<li>obtain version information about the CMSIS-RTOS API.</li>
<li>initialize of the RTOS kernel for creating objects.</li>
<li>start the RTOS kernel and thread switching.</li>
<li>check the execution status of the RTOS kernel.</li>
</ul>
<dl class="section note"><dt>Note</dt><dd>The kernel information and control functions cannot be called from <a class="el" href="theory_of_operation.html#CMSIS_RTOS_ISR_Calls">Interrupt Service Routines</a>. </dd>
<dd>
The kernel initialization for RTX5 is documented in <a class="el" href="theory_of_operation.html#SystemStartup">System Startup</a>.</dd></dl>
<p><b>Code Example</b> </p>
<div class="fragment"><div class="line"><span class="comment">/*----------------------------------------------------------------------------</span></div>
<div class="line"><span class="comment"> * Application main thread</span></div>
<div class="line"><span class="comment"> *---------------------------------------------------------------------------*/</span></div>
<div class="line"><span class="keywordtype">void</span> app_main (<span class="keywordtype">void</span> *argument) {</div>
<div class="line"> </div>
<div class="line">  <span class="comment">// ...</span></div>
<div class="line">  <span class="keywordflow">for</span> (;;) {}</div>
<div class="line">}</div>
<div class="line"> </div>
<div class="line"><span class="keywordtype">int</span> main (<span class="keywordtype">void</span>) {</div>
<div class="line"> </div>
<div class="line">  <span class="comment">// System Initialization</span></div>
<div class="line">  SystemCoreClockUpdate();</div>
<div class="line">  <span class="comment">// ...</span></div>
<div class="line"> </div>
<div class="line">  <a class="code" href="group__CMSIS__RTOS__KernelCtrl.html#gae818f6611d25ba3140bede410a52d659">osKernelInitialize</a>();                 <span class="comment">// Initialize CMSIS-RTOS</span></div>
<div class="line">  <a class="code" href="group__CMSIS__RTOS__ThreadMgmt.html#ga48d68b8666d99d28fa646ee1d2182b8f">osThreadNew</a>(app_main, NULL, NULL);    <span class="comment">// Create application main thread</span></div>
<div class="line">  <a class="code" href="group__CMSIS__RTOS__KernelCtrl.html#ga9ae2cc00f0d89d7b6a307bba942b5221">osKernelStart</a>();                      <span class="comment">// Start thread execution</span></div>
<div class="line">  <span class="keywordflow">for</span> (;;) {}</div>
<div class="line">}</div>
</div><!-- fragment --> <hr/><h2 class="groupheader">Data Structure Documentation</h2>
<a name="structosVersion__t" id="structosVersion__t"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">struct osVersion_t</td>
        </tr>
      </table>
</div><div class="memdoc">
<div class="textblock"><p>Identifies the underlying RTOS kernel and API version number. The version is represented in a combined decimal number in the format: major.minor.rev: mmnnnrrrr</p>
<p>Use <a class="el" href="group__CMSIS__RTOS__KernelCtrl.html#ga6f7764e7250c5c5364c00c45a5d1d199">osKernelGetInfo</a> to retrieve the version numbers. </p>
</div><table class="fieldtable">
<tr><th colspan="3">Data Fields</th></tr>
<tr><td class="fieldtype">
<a class="anchor" id="a76a1ef1a4d3d9bd3e70783051f22a6d3"></a>uint32_t</td>
<td class="fieldname">
api</td>
<td class="fielddoc">
API version (major.minor.rev: mmnnnrrrr dec). </td></tr>
<tr><td class="fieldtype">
<a class="anchor" id="ad8075d3f42141346ae2c56389358f9e7"></a>uint32_t</td>
<td class="fieldname">
kernel</td>
<td class="fielddoc">
Kernel version (major.minor.rev: mmnnnrrrr dec). </td></tr>
</table>

</div>
</div>
<h2 class="groupheader">Enumeration Type Documentation</h2>
<a class="anchor" id="ga08326469274b668140ca934b168a5ad4"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">enum <a class="el" href="group__CMSIS__RTOS__KernelCtrl.html#ga08326469274b668140ca934b168a5ad4">osKernelState_t</a></td>
        </tr>
      </table>
</div><div class="memdoc">
<p>State of the kernel as retrieved by <a class="el" href="group__CMSIS__RTOS__KernelCtrl.html#ga48b69b81012fce051f639be288b243ba">osKernelGetState</a>. In case <b>osKernelGetState</b> fails or if it is called from an ISR, it will return <code>osKernelError</code>, otherwise it returns the kernel state. </p>
<table class="fieldtable">
<tr><th colspan="2">Enumerator</th></tr><tr><td class="fieldname"><em><a class="anchor" id="ga08326469274b668140ca934b168a5ad4a2ad3e5912db47b497529d036c89e7995"></a>osKernelInactive</em>&#160;</td><td class="fielddoc">
<p>Inactive. </p>
<p>The kernel is not ready yet. <a class="el" href="group__CMSIS__RTOS__KernelCtrl.html#gae818f6611d25ba3140bede410a52d659">osKernelInitialize</a> needs to be executed successfully. </p>
</td></tr>
<tr><td class="fieldname"><em><a class="anchor" id="ga08326469274b668140ca934b168a5ad4a0596c6e14113447604753656417c9a24"></a>osKernelReady</em>&#160;</td><td class="fielddoc">
<p>Ready. </p>
<p>The kernel is not yet running. <a class="el" href="group__CMSIS__RTOS__KernelCtrl.html#ga9ae2cc00f0d89d7b6a307bba942b5221">osKernelStart</a> transfers the kernel to the running state. </p>
</td></tr>
<tr><td class="fieldname"><em><a class="anchor" id="ga08326469274b668140ca934b168a5ad4a8e0b699fbe1c8bb66fefadd5911cb6ce"></a>osKernelRunning</em>&#160;</td><td class="fielddoc">
<p>Running. </p>
<p>The kernel is initialized and running. </p>
</td></tr>
<tr><td class="fieldname"><em><a class="anchor" id="ga08326469274b668140ca934b168a5ad4a2fe382ad5ebab2257b35740414b28b01"></a>osKernelLocked</em>&#160;</td><td class="fielddoc">
<p>Locked. </p>
<p>The kernel was locked with <a class="el" href="group__CMSIS__RTOS__KernelCtrl.html#ga948609ee930d9b38336b9e1c2a4dfe12">osKernelLock</a>. The functions <a class="el" href="group__CMSIS__RTOS__KernelCtrl.html#gaf401728b4657456198c33fe75f8d6720">osKernelUnlock</a> or <a class="el" href="group__CMSIS__RTOS__KernelCtrl.html#gae7d0a71b9586cbbb49fcbdf6a04f0289">osKernelRestoreLock</a> unlocks it. </p>
</td></tr>
<tr><td class="fieldname"><em><a class="anchor" id="ga08326469274b668140ca934b168a5ad4ad364464ad84d63b1413a9ac8a962390c"></a>osKernelSuspended</em>&#160;</td><td class="fielddoc">
<p>Suspended. </p>
<p>The kernel was suspended using <a class="el" href="group__CMSIS__RTOS__KernelCtrl.html#gae26683e1606ec633354a2876c68f0c1f">osKernelSuspend</a>. The function <a class="el" href="group__CMSIS__RTOS__KernelCtrl.html#ga8c4b4d7ed34cab73c001665d9176aced">osKernelResume</a> returns to normal operation. </p>
</td></tr>
<tr><td class="fieldname"><em><a class="anchor" id="ga08326469274b668140ca934b168a5ad4a0545c92c18ce8e6b24e82a0d694a0b4a"></a>osKernelError</em>&#160;</td><td class="fielddoc">
<p>Error. </p>
<p>An error occurred. </p>
</td></tr>
<tr><td class="fieldname"><em><a class="anchor" id="ga08326469274b668140ca934b168a5ad4ab0a47576defa29396a649d9173d4bc4b"></a>osKernelReserved</em>&#160;</td><td class="fielddoc">
<p>Prevents enum down-size compiler optimization. </p>
<p>Reserved. </p>
</td></tr>
</table>

</div>
</div>
<h2 class="groupheader">Function Documentation</h2>
<a class="anchor" id="gae818f6611d25ba3140bede410a52d659"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="group__CMSIS__RTOS__Definitions.html#ga6c0dbe6069e4e7f47bb4cd32ae2b813e">osStatus_t</a> osKernelInitialize </td>
          <td>(</td>
          <td class="paramtype">void&#160;</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">
<dl class="section return"><dt>Returns</dt><dd>status code that indicates the execution status of the function.</dd></dl>
<p>The function <b>osKernelInitialize</b> initializes the RTOS Kernel. Before it is successfully executed, only the functions <a class="el" href="group__CMSIS__RTOS__KernelCtrl.html#ga6f7764e7250c5c5364c00c45a5d1d199">osKernelGetInfo</a> and <a class="el" href="group__CMSIS__RTOS__KernelCtrl.html#ga48b69b81012fce051f639be288b243ba">osKernelGetState</a> may be called.</p>
<p>Possible <a class="el" href="group__CMSIS__RTOS__Definitions.html#ga6c0dbe6069e4e7f47bb4cd32ae2b813e">osStatus_t</a> return values:</p>
<ul>
<li><em>osOK</em> in case of success.</li>
<li><em>osError</em> if an unspecific error occurred.</li>
<li><em>osErrorISR</em> if called from an <a class="el" href="theory_of_operation.html#CMSIS_RTOS_ISR_Calls">Interrupt Service Routine</a>.</li>
<li><em>osErrorNoMemory</em> if no memory could be reserved for the operation.</li>
</ul>
<dl class="section note"><dt>Note</dt><dd>This function <b>cannot</b> be called from <a class="el" href="theory_of_operation.html#CMSIS_RTOS_ISR_Calls">Interrupt Service Routines</a>.</dd></dl>
<p><b> Code Example</b> </p>
<div class="fragment"><div class="line"><span class="preprocessor">#include &quot;RTE_Components.h&quot;</span></div>
<div class="line"><span class="preprocessor">#include  CMSIS_device_header</span></div>
<div class="line"><span class="preprocessor"></span><span class="preprocessor">#include &quot;<a class="code" href="cmsis__os2_8h.html">cmsis_os2.h</a>&quot;</span></div>
<div class="line"> </div>
<div class="line"><span class="comment">/*----------------------------------------------------------------------------</span></div>
<div class="line"><span class="comment"> * Application main thread</span></div>
<div class="line"><span class="comment"> *---------------------------------------------------------------------------*/</span></div>
<div class="line"><span class="keywordtype">void</span> app_main (<span class="keywordtype">void</span> *argument) {</div>
<div class="line"> </div>
<div class="line">  <span class="comment">// ...</span></div>
<div class="line">  <span class="keywordflow">for</span> (;;) {}</div>
<div class="line">}</div>
<div class="line"> </div>
<div class="line"><span class="keywordtype">int</span> main (<span class="keywordtype">void</span>) {</div>
<div class="line"> </div>
<div class="line">  <span class="comment">// System Initialization</span></div>
<div class="line">  SystemCoreClockUpdate();</div>
<div class="line">  <span class="comment">// ...</span></div>
<div class="line"> </div>
<div class="line">  <a class="code" href="group__CMSIS__RTOS__KernelCtrl.html#gae818f6611d25ba3140bede410a52d659">osKernelInitialize</a>();                 <span class="comment">// Initialize CMSIS-RTOS</span></div>
<div class="line">  <a class="code" href="group__CMSIS__RTOS__ThreadMgmt.html#ga48d68b8666d99d28fa646ee1d2182b8f">osThreadNew</a>(app_main, NULL, NULL);    <span class="comment">// Create application main thread</span></div>
<div class="line">  <a class="code" href="group__CMSIS__RTOS__KernelCtrl.html#ga9ae2cc00f0d89d7b6a307bba942b5221">osKernelStart</a>();                      <span class="comment">// Start thread execution</span></div>
<div class="line">  <span class="keywordflow">for</span> (;;) {}</div>
<div class="line">}</div>
</div><!-- fragment --> 
</div>
</div>
<a class="anchor" id="ga6f7764e7250c5c5364c00c45a5d1d199"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="group__CMSIS__RTOS__Definitions.html#ga6c0dbe6069e4e7f47bb4cd32ae2b813e">osStatus_t</a> osKernelGetInfo </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="group__CMSIS__RTOS__KernelCtrl.html#structosVersion__t">osVersion_t</a> *&#160;</td>
          <td class="paramname"><em>version</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">char *&#160;</td>
          <td class="paramname"><em>id_buf</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">uint32_t&#160;</td>
          <td class="paramname"><em>id_size</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramdir">[out]</td><td class="paramname">version</td><td>pointer to buffer for retrieving version information. </td></tr>
    <tr><td class="paramdir">[out]</td><td class="paramname">id_buf</td><td>pointer to buffer for retrieving kernel identification string. </td></tr>
    <tr><td class="paramdir">[in]</td><td class="paramname">id_size</td><td>size of buffer for kernel identification string. </td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>status code that indicates the execution status of the function.</dd></dl>
<p>The function <b>osKernelGetInfo</b> retrieves the API and kernel version of the underlying RTOS kernel and a human readable identifier string for the kernel. It can be safely called before the RTOS is initialized or started (call to <a class="el" href="group__CMSIS__RTOS__KernelCtrl.html#gae818f6611d25ba3140bede410a52d659">osKernelInitialize</a> or <a class="el" href="group__CMSIS__RTOS__KernelCtrl.html#ga9ae2cc00f0d89d7b6a307bba942b5221">osKernelStart</a>).</p>
<p>Possible <a class="el" href="group__CMSIS__RTOS__Definitions.html#ga6c0dbe6069e4e7f47bb4cd32ae2b813e">osStatus_t</a> return values:</p>
<ul>
<li><em>osOK</em> in case of success.</li>
<li><em>osError</em> if an unspecific error occurred.</li>
</ul>
<dl class="section note"><dt>Note</dt><dd>This function may be called from <a class="el" href="theory_of_operation.html#CMSIS_RTOS_ISR_Calls">Interrupt Service Routines</a>.</dd></dl>
<p><b>Code Example</b> </p>
<div class="fragment"><div class="line"><span class="keywordtype">void</span> info (<span class="keywordtype">void</span>) {</div>
<div class="line">  <span class="keywordtype">char</span> infobuf[100];</div>
<div class="line">  <a class="code" href="group__CMSIS__RTOS__KernelCtrl.html#structosVersion__t">osVersion_t</a> osv;</div>
<div class="line">  osStatus_t status;</div>
<div class="line"> </div>
<div class="line">  status = <a class="code" href="group__CMSIS__RTOS__KernelCtrl.html#ga6f7764e7250c5c5364c00c45a5d1d199">osKernelGetInfo</a>(&amp;osv, infobuf, <span class="keyword">sizeof</span>(infobuf));</div>
<div class="line">  <span class="keywordflow">if</span>(status == <a class="code" href="cmsis__os2_8h.html#ga6c0dbe6069e4e7f47bb4cd32ae2b813ea9e1c9e2550bb4de8969a935acffc968f">osOK</a>) {</div>
<div class="line">    printf(<span class="stringliteral">&quot;Kernel Information: %s\r\n&quot;</span>, infobuf);</div>
<div class="line">    printf(<span class="stringliteral">&quot;Kernel Version    : %d\r\n&quot;</span>, osv.<a class="code" href="group__CMSIS__RTOS__KernelCtrl.html#ad8075d3f42141346ae2c56389358f9e7">kernel</a>);</div>
<div class="line">    printf(<span class="stringliteral">&quot;Kernel API Version: %d\r\n&quot;</span>, osv.<a class="code" href="group__CMSIS__RTOS__KernelCtrl.html#a76a1ef1a4d3d9bd3e70783051f22a6d3">api</a>);</div>
<div class="line">  }</div>
<div class="line">}</div>
</div><!-- fragment --> 
</div>
</div>
<a class="anchor" id="ga48b69b81012fce051f639be288b243ba"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="group__CMSIS__RTOS__KernelCtrl.html#ga08326469274b668140ca934b168a5ad4">osKernelState_t</a> osKernelGetState </td>
          <td>(</td>
          <td class="paramtype">void&#160;</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">
<dl class="section return"><dt>Returns</dt><dd>current RTOS Kernel state.</dd></dl>
<p>The function <b>osKernelGetState</b> returns the current state of the kernel and can be safely called before the RTOS is initialized or started (call to <a class="el" href="group__CMSIS__RTOS__KernelCtrl.html#gae818f6611d25ba3140bede410a52d659">osKernelInitialize</a> or <a class="el" href="group__CMSIS__RTOS__KernelCtrl.html#ga9ae2cc00f0d89d7b6a307bba942b5221">osKernelStart</a>). In case it fails it will return <code>osKernelError</code>, otherwise it returns the kernel state (refer to <a class="el" href="group__CMSIS__RTOS__KernelCtrl.html#ga08326469274b668140ca934b168a5ad4">osKernelState_t</a> for the list of kernel states).</p>
<p>Possible <a class="el" href="group__CMSIS__RTOS__KernelCtrl.html#ga08326469274b668140ca934b168a5ad4">osKernelState_t</a> return values:</p>
<ul>
<li><a class="el" href="cmsis__os2_8h.html#ga08326469274b668140ca934b168a5ad4a0545c92c18ce8e6b24e82a0d694a0b4a">osKernelError</a> if an unspecific error occurred.</li>
<li>the actual kernel state otherwise.</li>
</ul>
<dl class="section note"><dt>Note</dt><dd>This function may be called from <a class="el" href="theory_of_operation.html#CMSIS_RTOS_ISR_Calls">Interrupt Service Routines</a>.</dd></dl>
<p><b>Code Example</b> </p>
<div class="fragment"><div class="line"><span class="keywordtype">int</span> main (<span class="keywordtype">void</span>) {</div>
<div class="line">  <span class="comment">// System Initialization</span></div>
<div class="line">  SystemCoreClockUpdate();</div>
<div class="line">  <span class="comment">// ...</span></div>
<div class="line">  <span class="keywordflow">if</span>(<a class="code" href="group__CMSIS__RTOS__KernelCtrl.html#ga48b69b81012fce051f639be288b243ba">osKernelGetState</a>() == <a class="code" href="cmsis__os2_8h.html#ga08326469274b668140ca934b168a5ad4a2ad3e5912db47b497529d036c89e7995">osKernelInactive</a>) {     <span class="comment">// Is the kernel initialized?</span></div>
<div class="line">     <a class="code" href="group__CMSIS__RTOS__KernelCtrl.html#gae818f6611d25ba3140bede410a52d659">osKernelInitialize</a>();                         <span class="comment">// Initialize CMSIS-RTOS kernel</span></div>
<div class="line">  }</div>
<div class="line">  ;</div>
<div class="line">}</div>
</div><!-- fragment --> 
</div>
</div>
<a class="anchor" id="ga9ae2cc00f0d89d7b6a307bba942b5221"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="group__CMSIS__RTOS__Definitions.html#ga6c0dbe6069e4e7f47bb4cd32ae2b813e">osStatus_t</a> osKernelStart </td>
          <td>(</td>
          <td class="paramtype">void&#160;</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">
<dl class="section return"><dt>Returns</dt><dd>status code that indicates the execution status of the function.</dd></dl>
<p>The function <b>osKernelStart</b> starts the RTOS kernel and begins thread switching. It will not return to its calling function in case of success. Before it is successfully executed, only the functions <a class="el" href="group__CMSIS__RTOS__KernelCtrl.html#ga6f7764e7250c5c5364c00c45a5d1d199">osKernelGetInfo</a>, <a class="el" href="group__CMSIS__RTOS__KernelCtrl.html#ga48b69b81012fce051f639be288b243ba">osKernelGetState</a>, and object creation functions (<b>osXxxNew</b>) may be called.</p>
<p>At least one initial thread should be created prior osKernelStart, see <a class="el" href="group__CMSIS__RTOS__ThreadMgmt.html#ga48d68b8666d99d28fa646ee1d2182b8f">osThreadNew</a>.</p>
<p>Possible <a class="el" href="group__CMSIS__RTOS__Definitions.html#ga6c0dbe6069e4e7f47bb4cd32ae2b813e">osStatus_t</a> return values:</p>
<ul>
<li><em>osError</em> if an unspecific error occurred.</li>
<li><em>osErrorISR</em> if called from an <a class="el" href="theory_of_operation.html#CMSIS_RTOS_ISR_Calls">Interrupt Service Routine</a>.</li>
</ul>
<dl class="section note"><dt>Note</dt><dd>This function <b>cannot</b> be called from <a class="el" href="theory_of_operation.html#CMSIS_RTOS_ISR_Calls">Interrupt Service Routines</a>.</dd></dl>
<p><b>Code Example</b> </p>
<div class="fragment"><div class="line"><span class="keywordtype">int</span> main (<span class="keywordtype">void</span>) {</div>
<div class="line">  <span class="comment">// System Initialization</span></div>
<div class="line">  SystemCoreClockUpdate();</div>
<div class="line">  <span class="comment">// ...</span></div>
<div class="line">  <span class="keywordflow">if</span>(<a class="code" href="group__CMSIS__RTOS__KernelCtrl.html#ga48b69b81012fce051f639be288b243ba">osKernelGetState</a>() == <a class="code" href="cmsis__os2_8h.html#ga08326469274b668140ca934b168a5ad4a2ad3e5912db47b497529d036c89e7995">osKernelInactive</a>) {</div>
<div class="line">    <a class="code" href="group__CMSIS__RTOS__KernelCtrl.html#gae818f6611d25ba3140bede410a52d659">osKernelInitialize</a>();</div>
<div class="line">  }</div>
<div class="line">  ; <span class="comment">// ... Start Threads</span></div>
<div class="line">  <span class="keywordflow">if</span> (<a class="code" href="group__CMSIS__RTOS__KernelCtrl.html#ga48b69b81012fce051f639be288b243ba">osKernelGetState</a>() == <a class="code" href="cmsis__os2_8h.html#ga08326469274b668140ca934b168a5ad4a0596c6e14113447604753656417c9a24">osKernelReady</a>) {        <span class="comment">// If kernel is ready to run...</span></div>
<div class="line">    <a class="code" href="group__CMSIS__RTOS__KernelCtrl.html#ga9ae2cc00f0d89d7b6a307bba942b5221">osKernelStart</a>();                                <span class="comment">// ... start thread execution</span></div>
<div class="line">    }</div>
<div class="line">  </div>
<div class="line">  <span class="keywordflow">while</span>(1);                                         <span class="comment">// only reached in case of error</span></div>
<div class="line">}</div>
</div><!-- fragment --> 
</div>
</div>
<a class="anchor" id="ga948609ee930d9b38336b9e1c2a4dfe12"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">int32_t osKernelLock </td>
          <td>(</td>
          <td class="paramtype">void&#160;</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">
<dl class="section return"><dt>Returns</dt><dd>previous lock state (1 - locked, 0 - not locked, error code if negative).</dd></dl>
<p>The function <b>osKernelLock</b> allows to lock all task switches. It returns the previous value of the lock state (<span class="XML-Token">1</span> if it was locked, <span class="XML-Token">0</span> if it was unlocked), or a negative number representing an error code otherwise (refer to <a class="el" href="group__CMSIS__RTOS__Definitions.html#ga6c0dbe6069e4e7f47bb4cd32ae2b813e">osStatus_t</a>).</p>
<p>Possible <a class="el" href="group__CMSIS__RTOS__Definitions.html#ga6c0dbe6069e4e7f47bb4cd32ae2b813e">osStatus_t</a> return values:</p>
<ul>
<li><em>osError</em> if an unspecific error occurred.</li>
<li><em>osErrorISR</em> if called from an <a class="el" href="theory_of_operation.html#CMSIS_RTOS_ISR_Calls">Interrupt Service Routine</a>.</li>
</ul>
<dl class="section note"><dt>Note</dt><dd>This function <b>cannot</b> be called from <a class="el" href="theory_of_operation.html#CMSIS_RTOS_ISR_Calls">Interrupt Service Routines</a>.</dd></dl>
<p><b>Code Example</b> </p>
<div class="fragment"><div class="line">int32_t state = <a class="code" href="group__CMSIS__RTOS__KernelCtrl.html#ga948609ee930d9b38336b9e1c2a4dfe12">osKernelLock</a>();</div>
<div class="line"><span class="comment">// ... critical code</span></div>
<div class="line">osKernelRestore(state);</div>
</div><!-- fragment --> 
</div>
</div>
<a class="anchor" id="gaf401728b4657456198c33fe75f8d6720"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">int32_t osKernelUnlock </td>
          <td>(</td>
          <td class="paramtype">void&#160;</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">
<dl class="section return"><dt>Returns</dt><dd>previous lock state (1 - locked, 0 - not locked, error code if negative).</dd></dl>
<p>The function <b>osKernelUnlock</b> resumes from <a class="el" href="group__CMSIS__RTOS__KernelCtrl.html#ga948609ee930d9b38336b9e1c2a4dfe12">osKernelLock</a>. It returns the previous value of the lock state (<span class="XML-Token">1</span> if it was locked, <span class="XML-Token">0</span> if it was unlocked), or a negative number representing an error code otherwise (refer to <a class="el" href="group__CMSIS__RTOS__Definitions.html#ga6c0dbe6069e4e7f47bb4cd32ae2b813e">osStatus_t</a>).</p>
<p>Possible <a class="el" href="group__CMSIS__RTOS__Definitions.html#ga6c0dbe6069e4e7f47bb4cd32ae2b813e">osStatus_t</a> return values:</p>
<ul>
<li><em>osError</em> if an unspecific error occurred.</li>
<li><em>osErrorISR</em> if called from an <a class="el" href="theory_of_operation.html#CMSIS_RTOS_ISR_Calls">Interrupt Service Routine</a>.</li>
</ul>
<dl class="section note"><dt>Note</dt><dd>This function <b>cannot</b> be called from <a class="el" href="theory_of_operation.html#CMSIS_RTOS_ISR_Calls">Interrupt Service Routines</a>.</dd></dl>
<p><b>Code Example</b> </p>
<div class="fragment"><div class="line">int32_t sl = <a class="code" href="group__CMSIS__RTOS__KernelCtrl.html#ga948609ee930d9b38336b9e1c2a4dfe12">osKernelLock</a>();</div>
<div class="line"><span class="comment">// ... critical code</span></div>
<div class="line">{</div>
<div class="line">  int32_t su = <a class="code" href="group__CMSIS__RTOS__KernelCtrl.html#gaf401728b4657456198c33fe75f8d6720">osKernelUnlock</a>();</div>
<div class="line">  <span class="comment">// ... uncritical code</span></div>
<div class="line">  <a class="code" href="group__CMSIS__RTOS__KernelCtrl.html#gae7d0a71b9586cbbb49fcbdf6a04f0289">osKernelRestoreLock</a>(su);</div>
<div class="line">}</div>
<div class="line"><span class="comment">// ... critical code</span></div>
<div class="line"><a class="code" href="group__CMSIS__RTOS__KernelCtrl.html#gae7d0a71b9586cbbb49fcbdf6a04f0289">osKernelRestoreLock</a>(sl);</div>
</div><!-- fragment --> 
</div>
</div>
<a class="anchor" id="gae7d0a71b9586cbbb49fcbdf6a04f0289"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">int32_t osKernelRestoreLock </td>
          <td>(</td>
          <td class="paramtype">int32_t&#160;</td>
          <td class="paramname"><em>lock</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramdir">[in]</td><td class="paramname">lock</td><td>lock state obtained by <a class="el" href="group__CMSIS__RTOS__KernelCtrl.html#ga948609ee930d9b38336b9e1c2a4dfe12">osKernelLock</a> or <a class="el" href="group__CMSIS__RTOS__KernelCtrl.html#gaf401728b4657456198c33fe75f8d6720">osKernelUnlock</a>. </td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>new lock state (1 - locked, 0 - not locked, error code if negative).</dd></dl>
<p>The function <b>osKernelRestoreLock</b> restores the previous lock state after <a class="el" href="group__CMSIS__RTOS__KernelCtrl.html#ga948609ee930d9b38336b9e1c2a4dfe12">osKernelLock</a> or <a class="el" href="group__CMSIS__RTOS__KernelCtrl.html#gaf401728b4657456198c33fe75f8d6720">osKernelUnlock</a>.</p>
<p>The argument <em>lock</em> specifies the lock state as obtained by <a class="el" href="group__CMSIS__RTOS__KernelCtrl.html#ga948609ee930d9b38336b9e1c2a4dfe12">osKernelLock</a> or <a class="el" href="group__CMSIS__RTOS__KernelCtrl.html#gaf401728b4657456198c33fe75f8d6720">osKernelUnlock</a>.</p>
<p>The function returns the new value of the lock state (<span class="XML-Token">1</span> if it was locked, <span class="XML-Token">0</span> if it was unlocked), or a negative number representing an error code otherwise (refer to <a class="el" href="group__CMSIS__RTOS__Definitions.html#ga6c0dbe6069e4e7f47bb4cd32ae2b813e">osStatus_t</a>).</p>
<p>Possible <a class="el" href="group__CMSIS__RTOS__Definitions.html#ga6c0dbe6069e4e7f47bb4cd32ae2b813e">osStatus_t</a> return values:</p>
<ul>
<li><em>osError</em> if an unspecific error occurred.</li>
<li><em>osErrorISR</em> if called from an <a class="el" href="theory_of_operation.html#CMSIS_RTOS_ISR_Calls">Interrupt Service Routine</a>.</li>
</ul>
<dl class="section note"><dt>Note</dt><dd>This function <b>cannot</b> be called from <a class="el" href="theory_of_operation.html#CMSIS_RTOS_ISR_Calls">Interrupt Service Routines</a>.</dd></dl>
<p><b>Code Example</b> </p>
<div class="fragment"><div class="line">int32_t sl = <a class="code" href="group__CMSIS__RTOS__KernelCtrl.html#ga948609ee930d9b38336b9e1c2a4dfe12">osKernelLock</a>();</div>
<div class="line"><span class="comment">// ... critical code</span></div>
<div class="line">{</div>
<div class="line">  int32_t su = <a class="code" href="group__CMSIS__RTOS__KernelCtrl.html#gaf401728b4657456198c33fe75f8d6720">osKernelUnlock</a>();</div>
<div class="line">  <span class="comment">// ... uncritical code</span></div>
<div class="line">  <a class="code" href="group__CMSIS__RTOS__KernelCtrl.html#gae7d0a71b9586cbbb49fcbdf6a04f0289">osKernelRestoreLock</a>(su);</div>
<div class="line">}</div>
<div class="line"><span class="comment">// ... critical code</span></div>
<div class="line"><a class="code" href="group__CMSIS__RTOS__KernelCtrl.html#gae7d0a71b9586cbbb49fcbdf6a04f0289">osKernelRestoreLock</a>(sl);</div>
</div><!-- fragment --> 
</div>
</div>
<a class="anchor" id="gae26683e1606ec633354a2876c68f0c1f"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">uint32_t osKernelSuspend </td>
          <td>(</td>
          <td class="paramtype">void&#160;</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">
<dl class="section return"><dt>Returns</dt><dd>time in ticks, for how long the system can sleep or power-down.</dd></dl>
<p>CMSIS-RTOS provides extension for tick-less operation which is useful for applications that use extensively low-power modes where the SysTick timer is also disabled. To provide a time-tick in such power-saving modes a wake-up timer is used to derive timer intervals. The function <b>osKernelSuspend</b> suspends the RTX kernel scheduler and thus enables sleep modes.</p>
<p>The return value can be used to determine the amount of system ticks until the next tick-based kernel event will occure, i.e. a delayed thread becomed ready again. It is recommended to set up the low power timer to generate a wake-up interrupt based on this return value.</p>
<dl class="section note"><dt>Note</dt><dd>This function <b>cannot</b> be called from <a class="el" href="theory_of_operation.html#CMSIS_RTOS_ISR_Calls">Interrupt Service Routines</a>.</dd></dl>
<p><b>Code Example</b> </p>
<div class="fragment"><div class="line"><span class="keywordtype">void</span> <a class="code" href="group__rtx5__specific__functions.html#ga074068b8efa7074cee68a71481d0b072">osRtxIdleThread</a> (<span class="keywordtype">void</span>) {</div>
<div class="line">                                               <span class="comment">/* The idle thread is running</span></div>
<div class="line"><span class="comment">                                                  when no other thread is ready</span></div>
<div class="line"><span class="comment">                                                  to run.                      */</span></div>
<div class="line">  <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> sleep;</div>
<div class="line"> </div>
<div class="line">  <span class="keywordflow">for</span> (;;) {</div>
<div class="line">                                               <span class="comment">/* HERE: include optional user</span></div>
<div class="line"><span class="comment">                                                  code to be executed when no</span></div>
<div class="line"><span class="comment">                                                  task runs.                   */</span></div>
<div class="line">    sleep = <a class="code" href="group__CMSIS__RTOS__KernelCtrl.html#gae26683e1606ec633354a2876c68f0c1f">osKernelSuspend</a>();                 <span class="comment">/* Suspend RTX thread scheduler */</span></div>
<div class="line"> </div>
<div class="line">    <span class="keywordflow">if</span> (sleep) {                               <span class="comment">/* How long can we sleep?       */</span></div>
<div class="line">                                               <span class="comment">/* &quot;sleep&quot; is in RTX Timer Ticks</span></div>
<div class="line"><span class="comment">                                                  which is 1ms in this</span></div>
<div class="line"><span class="comment">                                                  configuration                */</span></div>
<div class="line">       </div>
<div class="line">                                               <span class="comment">/* Setup wake-up e.g. watchdog  */</span></div>
<div class="line"> </div>
<div class="line">      __WFE();                                 <span class="comment">/* Enter Power-down mode        */</span></div>
<div class="line">      </div>
<div class="line">                                               <span class="comment">/* After Wake-up                */</span></div>
<div class="line">      sleep = tc;                              <span class="comment">/* Adjust with cycles slept     */</span>  </div>
<div class="line">    }</div>
<div class="line"> </div>
<div class="line">    <a class="code" href="group__CMSIS__RTOS__KernelCtrl.html#ga8c4b4d7ed34cab73c001665d9176aced">osKernelResume</a>(sleep);                     <span class="comment">/* Resume thread scheduler      */</span></div>
<div class="line">  }</div>
<div class="line">}</div>
</div><!-- fragment --> 
</div>
</div>
<a class="anchor" id="ga8c4b4d7ed34cab73c001665d9176aced"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void osKernelResume </td>
          <td>(</td>
          <td class="paramtype">uint32_t&#160;</td>
          <td class="paramname"><em>sleep_ticks</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramdir">[in]</td><td class="paramname">sleep_ticks</td><td>time in ticks for how long the system was in sleep or power-down mode.</td></tr>
  </table>
  </dd>
</dl>
<p>CMSIS-RTOS provides extension for tick-less operation which is useful for applications that use extensively low-power modes where the SysTick timer is also disabled. To provide a time-tick in such power-saving modes a wake-up timer is used to derive timer intervals. The function <b>osKernelResume</b> enables the RTX kernel scheduler and thus wakes up the system from sleep mode.</p>
<dl class="section note"><dt>Note</dt><dd>This function <b>cannot</b> be called from <a class="el" href="theory_of_operation.html#CMSIS_RTOS_ISR_Calls">Interrupt Service Routines</a>.</dd></dl>
<p><b>Code Example</b> </p>
<div class="fragment"><div class="line"><span class="keywordtype">void</span> <a class="code" href="group__rtx5__specific__functions.html#ga074068b8efa7074cee68a71481d0b072">osRtxIdleThread</a> (<span class="keywordtype">void</span>) {</div>
<div class="line">                                               <span class="comment">/* The idle thread is running</span></div>
<div class="line"><span class="comment">                                                  when no other thread is ready</span></div>
<div class="line"><span class="comment">                                                  to run.                      */</span></div>
<div class="line">  <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> sleep;</div>
<div class="line"> </div>
<div class="line">  <span class="keywordflow">for</span> (;;) {</div>
<div class="line">                                               <span class="comment">/* HERE: include optional user</span></div>
<div class="line"><span class="comment">                                                  code to be executed when no</span></div>
<div class="line"><span class="comment">                                                  task runs.                   */</span></div>
<div class="line">    sleep = <a class="code" href="group__CMSIS__RTOS__KernelCtrl.html#gae26683e1606ec633354a2876c68f0c1f">osKernelSuspend</a>();                 <span class="comment">/* Suspend RTX thread scheduler */</span></div>
<div class="line"> </div>
<div class="line">    <span class="keywordflow">if</span> (sleep) {                               <span class="comment">/* How long can we sleep?       */</span></div>
<div class="line">                                               <span class="comment">/* &quot;sleep&quot; is in RTX Timer Ticks</span></div>
<div class="line"><span class="comment">                                                  which is 1ms in this</span></div>
<div class="line"><span class="comment">                                                  configuration                */</span></div>
<div class="line">       </div>
<div class="line">                                               <span class="comment">/* Setup wake-up e.g. watchdog  */</span></div>
<div class="line"> </div>
<div class="line">      __WFE();                                 <span class="comment">/* Enter Power-down mode        */</span></div>
<div class="line">      </div>
<div class="line">                                               <span class="comment">/* After Wake-up                */</span></div>
<div class="line">      sleep = tc;                              <span class="comment">/* Adjust with cycles slept     */</span>  </div>
<div class="line">    }</div>
<div class="line"> </div>
<div class="line">    <a class="code" href="group__CMSIS__RTOS__KernelCtrl.html#ga8c4b4d7ed34cab73c001665d9176aced">osKernelResume</a>(sleep);                     <span class="comment">/* Resume thread scheduler      */</span></div>
<div class="line">  }</div>
<div class="line">}</div>
</div><!-- fragment --> 
</div>
</div>
<a class="anchor" id="ga84bcdbf2fb76b10c8df4e439f0c7e11b"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">uint32_t osKernelGetTickCount </td>
          <td>(</td>
          <td class="paramtype">void&#160;</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">
<dl class="section return"><dt>Returns</dt><dd>RTOS kernel current tick count.</dd></dl>
<p>The function <b>osKernelGetTickCount</b> returns the current RTOS kernel tick count.</p>
<dl class="section note"><dt>Note</dt><dd>This function may be called from <a class="el" href="theory_of_operation.html#CMSIS_RTOS_ISR_Calls">Interrupt Service Routines</a>.</dd></dl>
<p><b>Code</b> <b>Example</b> </p>
<div class="fragment"><div class="line"><span class="preprocessor">#include &quot;<a class="code" href="cmsis__os2_8h.html">cmsis_os2.h</a>&quot;</span></div>
<div class="line"> </div>
<div class="line"><span class="keywordtype">void</span> Thread_1 (<span class="keywordtype">void</span> *arg)  {                <span class="comment">// Thread function</span></div>
<div class="line">  uint32_t tick;</div>
<div class="line"></div>
<div class="line">  tick = <a class="code" href="group__CMSIS__RTOS__KernelCtrl.html#ga84bcdbf2fb76b10c8df4e439f0c7e11b">osKernelGetTickCount</a>();            <span class="comment">// retrieve the number of system ticks</span></div>
<div class="line">  <span class="keywordflow">for</span> (;;) {</div>
<div class="line">    tick += 1000;                           <span class="comment">// delay 1000 ticks periodically</span></div>
<div class="line">    <a class="code" href="group__CMSIS__RTOS__Wait.html#ga3c807924c2d6d43bc2ffb49da3f7f3a1">osDelayUntil</a>(tick);</div>
<div class="line">    <span class="comment">// ...</span></div>
<div class="line">  }</div>
<div class="line">}</div>
</div><!-- fragment --><p>Due to the limited value range used for the tick count it may overflow during runtime, i.e. after 2<sup>32</sup> ticks which are roughly 49days @ 1ms. Typically one has not to take special care of this unless a monotonic counter is needed. For such a case an additional 64bit tick counter can be implemented as follows. The given example needs GetTick() called at least twice per tick overflow to work properly.</p>
<p><b>Code</b> <b>Example</b> </p>
<div class="fragment"><div class="line">uint64_t GetTick(<span class="keywordtype">void</span>) {</div>
<div class="line">  <span class="keyword">static</span> uint32_t tick_h = 0U;</div>
<div class="line">  <span class="keyword">static</span> uint32_t tick_l = 0U;</div>
<div class="line">         uint32_t tick;</div>
<div class="line"></div>
<div class="line">  tick = <a class="code" href="group__CMSIS__RTOS__KernelCtrl.html#ga84bcdbf2fb76b10c8df4e439f0c7e11b">osKernelGetTickCount</a>();</div>
<div class="line">  <span class="keywordflow">if</span> (tick &lt; tick_l) {</div>
<div class="line">    tick_h++;</div>
<div class="line">  }</div>
<div class="line">  tick_l = tick;</div>
<div class="line"></div>
<div class="line">  <span class="keywordflow">return</span> (((uint64_t)tick_h &lt;&lt; 32) | tick_l);</div>
<div class="line">}</div>
</div><!-- fragment --> 
</div>
</div>
<a class="anchor" id="ga7a8d7bd927eaaa58999f91d7d6310cee"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">uint32_t osKernelGetTickFreq </td>
          <td>(</td>
          <td class="paramtype">void&#160;</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">
<dl class="section return"><dt>Returns</dt><dd>frequency of the kernel tick in hertz, i.e. kernel ticks per second.</dd></dl>
<p>The function <b>osKernelGetTickFreq</b> returns the frequency of the current RTOS kernel tick.</p>
<dl class="section note"><dt>Note</dt><dd>This function may be called from <a class="el" href="theory_of_operation.html#CMSIS_RTOS_ISR_Calls">Interrupt Service Routines</a>. </dd></dl>

</div>
</div>
<a class="anchor" id="gae0fcaff6cecfb4013bb556c87afcd7d2"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">uint32_t osKernelGetSysTimerCount </td>
          <td>(</td>
          <td class="paramtype">void&#160;</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">
<dl class="section return"><dt>Returns</dt><dd>RTOS kernel current system timer count as 32-bit value.</dd></dl>
<p>The function <b>osKernelGetSysTimerCount</b> returns the current RTOS kernel system timer as a 32-bit value.</p>
<dl class="section note"><dt>Note</dt><dd>This function may be called from <a class="el" href="theory_of_operation.html#CMSIS_RTOS_ISR_Calls">Interrupt Service Routines</a>. </dd></dl>

</div>
</div>
<a class="anchor" id="ga4d69215a93220f72be3684cad582f16a"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">uint32_t osKernelGetSysTimerFreq </td>
          <td>(</td>
          <td class="paramtype">void&#160;</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">
<dl class="section return"><dt>Returns</dt><dd>frequency of the system timer in hertz, i.e. timer ticks per second.</dd></dl>
<p>The function <b>osKernelGetSysTimerFreq</b> returns the frequency of the current RTOS kernel system timer.</p>
<dl class="section note"><dt>Note</dt><dd>This function may be called from <a class="el" href="theory_of_operation.html#CMSIS_RTOS_ISR_Calls">Interrupt Service Routines</a>. </dd></dl>

</div>
</div>
</div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="footer">Generated on Wed Jul 10 2019 15:21:04 for CMSIS-RTOS2 Version 2.1.3 by Arm Ltd. All rights reserved.
	<!--
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.6 
	-->
	</li>
  </ul>
</div>
</body>
</html>
